<!DOCTYPE html>
<html class="x-admin-sm">

    <head>
        <meta charset="UTF-8">
        <title>数据设置</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!--        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />-->
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
        <script type="text/javascript" src="./js/jquery.min.js"></script>
        <script type="text/javascript" src="./data/sensor.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->

    </head>

    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">数据库数据管理</a>
                <a>
                    <cite>数据库数据管理</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            选择操作项:<select id="select_qiti" style="width: 100px;height: 20px">
                                            <option value="CH4">CH4</option>
                                            <option value="CO2">CO2</option>
                                            <option value="CO">CO</option>
                                            <option value="temperature">温度</option>
                                            <option value="humidity">湿度</option>
                                            <option value="O2">氧气</option>
                                 </select>

                            选择日期:&nbsp; <input type="date" id="searchDate" style="height: 20px">

                            选择班次:<select id="select_banci" style="width: 100px;height: 20px">
                                        <option value="0">0点班</option>
                                        <option value="8">8点班</option>
                                        <option value="16">16点班</option>
                               </select>
                               <button type="button" class="layui-btn"  onclick="exportReport()">导出</button>

                        </div>
                        <div class="layui-card-body ">
                            <table id="demo" class="layui-table" lay-filter="test_table" ></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script type="text/html" id="toolbarMenu">
        <div class = "layui-btn-container" >
<!--            <button class = "layui-btn layui-btn-sm" lay-event = "getCheckData" > 获取选中行数据 </button>-->
<!--            <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button >-->
<!--            <button class = "layui-btn layui-btn-sm" lay-event = "addSensor" onclick="xadmin.open('添加设备','./sensor-add.html',600,400)" ><i class="layui-icon"></i> 新增传感器</button>-->
        </div >
    </script>
    <script type="text/html" id="toolbarDemo">


        <div class = "layui-btn-container" >

<!--            <button class = "layui-btn layui-btn-sm" lay-event = "getCheckData" > 获取选中行数据 </button>-->
        </div >
    </script>


    <script type="text/javascript">

        function initSensorList(dataSensor){
            layui.use('table', function () {
                var table = layui.table;
                //第一个实例
                table.render({
                    elem: '#demo'
                    ,
                    height: 450
                    , data: dataSensor,
                    page: false //开启分页
                    ,limit: 100,
                    toolbar: '#toolbarMenu',
                    cols: [[ //表头
                          // {field: 'id', title: '编号', width: 80, sort: true, fixed: 'left'}
                        // ,
                         {field: 'address', title: '地址', width: 150}
                        , {field: 'day', title: '日期', width: 100}
                        , {field: 'shiftnumber', title: '检查次数', width: 80}
                        , {field: 'maxch4', title: '甲烷(MAX)', width: 120}
                        , {field: 'maxco', title: '一氧化碳(MAX)', width: 120}
                        , {field: 'maxco2', title: '二氧化碳(MAX)', width: 120}
                        , {field: 'maxhumidity', title: '湿度(MAX)', width: 120}
                        , {field: 'maxtemperature', title: '温度(MAX)', width: 100}
                        , {field: 'mino2', title: '氧气(MIN)', width: 100}
                        // , {field: '', title: '编辑', width: 150, sort: true, toolbar:'#toolbarDemo'}
                    ]]
                    ,loading:true
                });

                //头工具栏事件
                table.on('toolbar(toolbarDemo)', function(obj) {
                    var checkStatus = table.checkStatus(obj.config.pid);
                    switch (obj.event) {
                        case 'delete':
                            layer.msg('data:'+obj.data.pid);
                            del(obj);
                            break;
                    };
                });
                //列里的工具栏
                // table.on('tool(test_table)',
                //     function(obj) {
                //         //var checkStatus = table.checkStatus(obj.config.pid);
                //         switch (obj.event) {
                //             case 'delete':
                //                 layer.msg('data:'+obj.data.pid);
                //                 del(obj);
                //                 break;
                //         };
                //     });
            });
        }

        function getData(){
             dataSensor=sensorServer.getSensorDataListByByBanci({"page":1,"rows":1000});
             return dataSensor;
        }
        //加载默认数据
        $(function () {
            var  dataSensor=getData();
            if (dataSensor!=null&&dataSensor!=undefined){
                initSensorList(dataSensor.data);
            }else{
                layer.msg('加载失败！!',{icon:1,time:1000});
            }
            initSelectData();
        })


        function sensorInfo(pid,deviceId){
            this.pid=pid;
            this.deviceId=deviceId;
        }

        //导出操作
        function exportReport() {
            var seText=$("#searchDate").val();
            var modelPath=$("#select_model").val();
            var banci=$("#select_banci").val();
            sensorServer.exportReportByModel(modelPath,seText,banci);
        }

        //初始化模板列表
        function  initSelectData() {
            var resultDataInfo=sensorServer.getReportModeList({"page":1,"rows":10});
            if (resultDataInfo!=null) {
                let optionList="";
                for(let i=0;i<resultDataInfo.data.length;i++){
                    optionList+="<option value='"+resultDataInfo.data[i].modelPath+"'>"+resultDataInfo.data[i].modelName+"</option>";
                }
                $("#select_model").append(optionList);
            }
        }
    </script>



</html>
